#ifdef WITH_OPENGL
#pragma once

// EXTENSION_SET specifies the set of extensions to use
//
// - VERSION_EXTENSIONS only loads version upgrades
// - MAX_VERSION_EXTENSIONS only loads the version upgrades up untill this value
// - VERSION_1_2_EXTENSIONS loads all extension upto and including opengl 1.2
// - VERSION_1_3_EXTENSIONS loads all extension upto and including opengl 1.3
// - VERSION_1_4_EXTENSIONS loads all extension upto and including opengl 1.4
// - VERSION_1_5_EXTENSIONS loads all extension upto and including opengl 1.5
// - VERSION_2_0_EXTENSIONS loads all extension upto and including opengl 2.0
// - VERSION_2_1_EXTENSIONS loads all extension upto and including opengl 2.1
// - CRITICAL_EXTENSIONS only loads ARB and version upgrades
// - IMPORTANT_EXTENSIONS only loads EXT, ARB and version upgrades
// - ARB_EXTENSIONS only loads ARB extensions
// - EXT_EXTENSIONS only loads EXT extensions
// - ALL_EXTENSIONS loads all possible extensions (including vendor specific)
#define EXTENSION_SET CRITICAL_EXTENSIONS

// Set the maximum version of opengl supported by this application can be
// one of (VERSION_1_2, VERSION_1_3, VERSION_1_4, VERSION_1_5, VERSION_2_0 or VERSION_2_1)
#define MAX_VERSION_EXTENSIONS VERSION_1_3

// I'm not happy with this being here. However the compiler starts 
// to complain because it's missing WINGDIAPI and APIENTRY in the 
// headerfile or whatever. *angry*
#ifdef _WIN32
#include <windows.h>
#endif

// I know OS X wants this file in OpenGl/GL.h or whatever :-/ nice...
#include <gl/gl.h>
#include <vector>
#include <string>
#include "glext.h"

#define DECLARE_CONST(name, value) \
	static const int name = value;

#define TYPEDEF_FUNCTION_POINTER_AND_EXTERN(ret, name, type, params) \
	typedef ret (APIENTRY * fptr_##type##_t) params; \
	extern fptr_##type##_t name;

// Generate all the contants and generate a list of function pointers and typedefs
// (in global space because opengl functions are in global space too)
EXTENSION_SET(NAME_EMPTY, TYPEDEF_FUNCTION_POINTER_AND_EXTERN, DECLARE_CONST, END_EMPTY)

namespace krryn{
namespace system{
	class opengl_helper{
	public:
		// a_Available is a list of extensions available on this system.
		// load_extensions will try to load in all the function pointers belonging
		// to those extensions.
		//
		// Notice that the constants are loaded even though the extension might not
		// be supported on the users system.
		//
		// This function then returns a list of names of all the function pointers
		// it couldn't load. (For example for debugging).
		static std::vector<std::string> load_extensions(const std::vector<std::string> &a_Available);
	private:
		static void *get_proc_address(const char *a_ProcName);
	};
}
}

#endif